/* eslint-disable no-dupe-keys */
<template>
  <div class="app-container">
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="姓名" prop="personName">
        <el-input
          v-model="queryParams.personName"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="类别" prop="detectionCycleId">
        <el-select
          v-model="queryParams.detectionCycleId"
          filterable
          placeholder="请选择类别"
        >
          <el-option
            v-for="item in category"
            :key="item.id"
            :label="item.categoryName"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号码" label-width="100" prop="cardId">
        <el-input
          v-model="queryParams.cardId"
          placeholder="请输入身份证号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phoneNumber">
        <el-input
          v-model="queryParams.phoneNumber"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属部门">
        <el-cascader
          :options="hangye"
          v-model="queryParams.deptId"
          :show-all-levels="false"
          :props="{ checkStrictly: true, emitPath: false, value: 'id' }"
          clearable
          @change="handleChangeDept"
        ></el-cascader>
      </el-form-item>
      <el-form-item label="负责人">
        <el-input
          v-model="chargeName"
          clearable
          size="small"
          placeholder="暂无"
          readonly
        />
      </el-form-item>
      <el-form-item label="审核状态" prop="examine">
        <el-select
          v-model="queryParams.examine"
          filterable
          placeholder="请选择审核状态"
        >
          <el-option
            v-for="item in examinearr"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="检测状态" prop="falg">
        <el-select
          v-model="queryParams.falg"
          filterable
          placeholder="请选择检测状态"
        >
          <el-option
            v-for="item in jiancetype"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="检测时间" prop="detectionTime">
        <el-date-picker
          v-model="queryParams.detectionTimes"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <div
      style="
        display: flex;
        justify-content: space-between;
        margin-bottom: 15px;
        align-items: center;
      "
    >
      <div>
        <el-button
          v-hasPermi="['system:person:add']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
        <el-button
          v-hasPermi="['system:person:import']"
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          >导入</el-button
        >
        <el-button
          v-hasPermi="['system:person:checkexcel']"
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImportS"
          >校验数据</el-button
        >
        <el-button
          v-hasPermi="['system:person:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          >导出</el-button
        >
        <el-button
          v-hasPermi="['system:person:remove']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="ids.length < 1"
          :loading="exportLoading"
          @click="handleDeleteMultiple"
          >删除</el-button
        >
        <el-button
          v-hasPermi="['system:person:truncateTable']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :loading="exportLoading"
          @click="getTruncateTable"
          >清空数据</el-button
        >
      </div>
      <div style="display: flex; align-items: center">
        <div style="margin-right: 15px; display: inline-block; color: #606266">
          共{{ total }}人 {{ yj }}人已完成 {{ wj }}人未完成
        </div>
        <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
      </div>
    </div>
    <el-table
      v-loading="loading"
      :data="personList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="50" align="center" />
      <el-table-column
        label="姓名"
        align="center"
        prop="personName"
        width="100"
      />
      <el-table-column
        label="类别"
        align="center"
        prop="detectioncycleName"
        width="120"
      >
        <template slot-scope="{ row }">
          {{
            (row.detectionCycleList &&
              row.detectionCycleList.length > 0 &&
              row.detectionCycleList[0].categoryName) ||
            ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="身份证号码"
        align="center"
        prop="cardId"
        width="170"
      />
      <el-table-column
        label="手机号码"
        align="center"
        prop="phoneNumber"
        width="150"
      />
      <el-table-column
        label="工作单位所在网格"
        align="center"
        prop="workGrid"
        width="150"
      />
      <el-table-column
        label="住地所在网格"
        align="center"
        prop="addressGrid"
        width="150"
      />
      <el-table-column
        label="所属部门"
        align="center"
        prop="deptName"
        width="400"
      />
      <el-table-column label="检测状态" align="center" prop="falg">
        <template slot-scope="scope">
          <span v-if="scope.row.falg == 1" style="color: #ff8800">未完成</span>
          <span v-if="scope.row.falg == 0" style="color: green">已完成</span>
        </template>
      </el-table-column>
      <el-table-column label="当期应检(次)" align="center" width="130">
        <template slot-scope="{ row }">
          {{
            (row.detectionCycleList &&
              row.detectionCycleList.length > 0 &&
              row.detectionCycleList[0].frequency) ||
            ""
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="当期已检(次)"
        width="130"
        align="center"
        prop="frequency"
      />
      <el-table-column
        label="数据来源"
        align="center"
        prop="source"
        width="120"
      >
        <template slot-scope="{ row }">
          {{ row.source | sourceFilter }}
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="examine">
        <template slot-scope="scope">
          <span v-if="scope.row.examine === 0" style="color: green"
            >审核通过</span
          >
          <span v-if="scope.row.examine === 1" style="color: #ff8800"
            >未审核</span
          >
          <span v-if="scope.row.examine === 2" style="color: red"
            >审核未通过</span
          >
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="220"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="['system:person:query']"
            @click="handleKan(scope.row)"
            >查看</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            v-hasPermi="['system:person:edit']"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-del"
            v-hasPermi="['system:person:remove']"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
          <el-button
            v-if="scope.row.examine == 1"
            v-hasPermi="['system:person:examine']"
            size="mini"
            type="text"
            icon="el-icon-del"
            @click="toexamine(scope.row)"
            >审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 查看 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="500px"
      custom-class="dialog-internal-scroll"
      top="0"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="姓名" prop="personName">
          <div>{{ form.personName }}</div>
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <div>{{ form.sex }}</div>
        </el-form-item>
        <el-form-item label="年龄" prop="personAge">
          <div>{{ form.personAge }}</div>
        </el-form-item>
        <el-form-item label="类别" prop="detectioncycleName">
          <div>
            {{
              form.detectionCycleList &&
              form.detectionCycleList.length > 0 &&
              form.detectionCycleList[0].categoryName
            }}
          </div>
        </el-form-item>
        <el-form-item label="工作地点" prop="workAddress">
          <div>{{ form.workAddress }}</div>
        </el-form-item>
        <el-form-item label="身份证号码" prop="cardId">
          <div>{{ form.cardId }}</div>
        </el-form-item>
        <el-form-item label="手机号码" prop="phoneNumber">
          <div>{{ form.phoneNumber }}</div>
        </el-form-item>
        <el-form-item label="家庭住址" prop="address">
          <div>{{ form.address }}</div>
        </el-form-item>
        <el-form-item label="所属部门" prop="deptName">
          <div>{{ form.deptName }}</div>
        </el-form-item>
        <el-form-item label="企业名称" prop="enterpriseName">
          <div>{{ form.enterpriseName }}</div>
        </el-form-item>
        <el-form-item label="核酸信息">
          <div v-if="!form.ptestingList || form.ptestingList.length === 0">
            未查到
          </div>
          <div v-for="(item, index) in form.ptestingList" :key="index">
            <span>检测日期：{{ item.detectionTime }}</span>
            <span style="margin-left: 20px">{{
              item.detectionResult == "1" ? "阴性" : "阳性"
            }}</span>
          </div>
        </el-form-item>
      </el-form>
    </el-dialog>
    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="openedit"
      width="500px"
      append-to-body
      custom-class="dialog-internal-scroll"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="personName">
          <el-input v-model="form.personName" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="sex">
          <el-select
            v-model="form.sex"
            placeholder="请选择性别"
            style="width: 100%"
          >
            <el-option label="男" value="男" />
            <el-option label="女" value="女" />
          </el-select>
        </el-form-item>
        <el-form-item label="年龄" prop="personAge">
          <el-input
            v-model="form.personAge"
            type="number"
            placeholder="请输入年龄"
          />
        </el-form-item>
        <el-form-item label="类别" prop="detectionCycleId">
          <el-select
            v-model="form.detectionCycleId"
            filterable
            placeholder="请选择"
            style="width: 100%"
          >
            <el-option
              v-for="item in category"
              :key="item.id"
              :label="item.categoryName"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="工作地点" prop="workAddress">
          <el-input v-model="form.workAddress" placeholder="请输入工作地点" />
        </el-form-item>
        <el-form-item label="身份证号" prop="cardId">
          <el-input v-model="form.cardId" placeholder="请输入身份证号码" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phoneNumber">
          <el-input
            v-model="form.phoneNumber"
            type="number"
            placeholder="请输入手机号码"
          />
        </el-form-item>
        <el-form-item label="家庭住址" prop="address">
          <el-input v-model="form.address" placeholder="请输入家庭住址" />
        </el-form-item>
        <el-form-item label="单位所在网格" prop="workGrid">
          <el-input v-model="form.workGrid" placeholder="请输入工作单位所在网格" />
        </el-form-item>
        <el-form-item label="住址所在网格" prop="addressGrid">
          <el-input v-model="form.addressGrid" placeholder="请输入住址所在网格" />
        </el-form-item>
        <el-form-item label="所属部门" prop="deptId">
          <select-tree
            v-if="openedit"
            v-model="form.deptId"
            :options="hangye"
            @emitindustryList="emitindustryList"
            :props="{ value: 'id', label: 'label', children: 'children' }"
          />
          <!-- :props="industry"  此属性不知道作用是什么，后期需要用自己添加-->
        </el-form-item>
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input
            v-model="form.enterpriseName"
            placeholder="请输入企业名称"
          />
        </el-form-item>
      </el-form>
      <div style="text-align: right">
        <el-button
          v-hasPermi="['system:person:add']"
          type="primary"
          plain
          size="mini"
          @click="submitForm"
          >提交</el-button
        >
      </div>
    </el-dialog>
    <!-- 防控信息导入对话框 -->
    <el-dialog
      :title="upload.title"
      :visible.sync="upload.open"
      width="400px"
      append-to-body
      custom-class="dialog-internal-scroll"
    >
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.isVerification?upload.url:(upload.url + '?updateSupport=' + upload.updateSupport)"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload" />
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div slot="tip" class="el-upload__tip text-center" v-if="!upload.isVerification">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link
            type="primary"
            :underline="false"
            style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate"
            >下载模板</el-link
          >
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 审核弹框 -->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
      <span>是否审核通过</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="adopt">通 过</el-button>
      </span>
    </el-dialog>
    <!-- 删除 -->
    <el-dialog title="提示" :visible.sync="dialogdel" width="30%">
      <span>是否确认删除，请输入删除理由</span>
      <el-input
        v-model="reason"
        placeholder="请输入删除理由"
        style="margin-top: 20px"
      />
      <span slot="footer" class="dialog-footer">
        <el-button @click="delcal">取 消</el-button>
        <el-button type="primary" @click="delsure">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog title="提示" :visible.sync="dialogdelA" width="30%">
      <span>是否确认清空重点人群</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="delcalA">取 消</el-button>
        <el-button type="primary" @click="delsureA">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
const baseURL = process.env.VUE_APP_BASE_API;
let downloadLoadingInstance;
import {
  getTruncateTable,
  listPerson,
  getPerson,
  removePerson,
  addPerson,
  updatePerson,
  exportPerson,
  importTemplate,
  personchargelist,
  categorychargelist,
  getCharge,
} from "@/api/control/person";
import { Loading } from 'element-ui'
import { getToken } from "@/utils/auth";
import SelectTree from "@/components/selecttree.vue";
import Tree from "@/components/selecttreesech.vue";
import { treeselectrole } from "@/api/control/dept";
export default {
  name: "Person",
  components: {
    SelectTree,
    Tree,
  },
  filters: {
    sourceFilter(status) {
      const statusMap = {
        0: "PC新增",
        1: "PC导入",
        2: "小程序录入",
        3: "经营录入",
      };
      return statusMap[status];
    },
  },
  data() {
    return {
      dialogdel: false,
      dialogdelA: false,
      reason: "", // 删除理由
      personIdaaa: "", // 删除id
      dialogVisible: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      personList: [],
      // 弹出层标题
      title: "",
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 是否是校验弹窗
        isVerification: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/person/importData",
      },
      // 是否显示弹出层
      open: false,
      openedit: false,
      hangye: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        delFlag: 0,
        openId: null,
        personName: null,
        personAge: null,
        workAddress: null,
        cardId: null,
        phoneNumber: null,
        address: null,
        category: null,
        detectionTime3: null,
        detectionAddress: null,
        detectionNumber: null,
        industry: null,
        enterpriseName: null,
        organization: null,
        // eslint-disable-next-line no-dupe-keys
        category: null,
        deptId: null,
        detectionCycleId: null,
        chargeId: null,
      },
      charge: "",
      // 表单参数
      form: {
        deptId: "",
      },
      // 表单校验
      rules: {
        cardId: [
          {
            pattern:
              /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
            required: true,
            message: "请输入正确的身份证号",
            trigger: "blur",
          },
        ],
        phoneNumber: [
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            required: true,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
        deptId: [
          {
            required: true,
            message: "请选择行业",
          },
        ],
        detectionCycleId: [
          {
            required: true,
            message: "请选择类别",
          },
        ],
      },
      fuzeren: [],
      category: [],
      examinearr: [
        {
          name: "审核通过",
          id: 0,
        },
        {
          name: "未审核",
          id: 1,
        },
      ],
      personIdsss: "",
      jiancetype: [
        {
          name: "未完成",
          id: 1,
        },
        {
          name: "已完成",
          id: 0,
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      chargeName: "",
      wj: 0,
      yj: 0,
    };
  },
  created() {
    this.getList();
    // this.personchargeList();
    this.categorychargeList();
    this.getTreeSelect();
  },
  methods: {
    handleChangeDept(val) {
      console.log(val);
      if (!val) {
        this.chargeName = "";
      } else {
        getCharge(val).then((res) => {
          if (res.data) {
            this.chargeName = res.data.nickName;
          } else {
            this.chargeName = "";
          }
        });
      }
    },
    // 获取所有部门
    getTreeSelect() {
      treeselectrole().then((res) => {
        res.data.forEach((item) => {
          if (!item.children) {
            item.children = [];
          }
        });
        this.hangye = res.data;
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有防控数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          downloadLoadingInstance = Loading.service({
            text: "正在导出数据，请稍候",
            spinner: "el-icon-loading",
            background: "rgba(0, 0, 0, 0.7)",
          });

          return exportPerson(queryParams);
        })
        .then((response) => {
          window.location.href =
            baseURL +
            "/common/download?fileName=" +
            encodeURI(response.msg) +
            "&delete=" +
            true;
          this.exportLoading = false;
          downloadLoadingInstance.close();
        })
        .catch(() => {
          this.exportLoading = false;
          downloadLoadingInstance.close();
        });
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "防控信息导入";
      this.upload.url= process.env.VUE_APP_BASE_API + "/system/person/importData"
      this.upload.isVerification=false;
      this.upload.open = true;
    },
    /** 校验按钮操作 */
    handleImportS() {
      this.upload.title = "数据校验";
      this.upload.open = true;
      this.upload.url= process.env.VUE_APP_BASE_API + "/system/person/checkExcel"
      this.upload.isVerification=true;
    },
    /** 下载模板操作 */
    importTemplate() {
      importTemplate().then((response) => {
        window.location.href =
          baseURL +
          "/common/download?fileName=" +
          encodeURI(response.msg) +
          "&delete=" +
          true;
        // this.download(response.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      downloadLoadingInstance = Loading.service({
        text: "正在上传数据，请稍候",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)",
      });
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      if (this.upload.isVerification){
        this.msgSuccess("校验完成！校验结果请查看excel");
        window.location.href =
          baseURL +
          "/common/download?fileName=" +
          encodeURI(response.msg) +
          "&delete=" +
          true;
      }else {
        this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      }
      this.getList();
      downloadLoadingInstance.close()

    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listPerson({
        ...this.queryParams,
      }).then((response) => {
        this.personList = response.rows;
        this.total = response.total;
        this.wj = response.wj;
        this.yj = response.yj;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openedit = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        personId: null,
        openId: null,
        personName: null,
        personAge: null,
        workAddress: null,
        cardId: null,
        phoneNumber: null,
        address: null,
        category: null,
        detectionTime3: null,
        detectionAddress: null,
        detectionNumber: null,
        industry: null,
        enterpriseName: null,
        createTime: null,
        deptId: null,
        category: null,
        detectionCycleId: null,
      };
      this.resetForm("form");
    },
    emitindustryList(res) {
      this.form.industryList = res;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.deptId = null;
      this.chargeName = "";
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.personId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.openedit = true;
      this.title = "添加";
    },
    /** 按钮操作 */
    handleKan(row) {
      this.reset();
      const personId = row.personId || this.ids;
      getPerson(personId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "查看";
      });
    },
    /** 按钮操作 */
    handleUpdate(row) {
      this.reset();
      const personId = row.personId || this.ids;
      getPerson(personId).then((response) => {
        this.form = response.data;
        this.form.deptId = Number(response.data.deptId);
        this.form.detectionCycleId =
          Number(response.data.detectionCycleId) || "";
        if (response.data.chargeId) {
          this.form.chargeId = Number(response.data.chargeId);
        } else {
          this.form.chargeId = response.data.chargeId;
        }
        this.openedit = true;
        this.title = "修改";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.personId != null) {
            if (this.form.personName == "" || this.form.personName == null) {
              this.msgError("姓名不能为空！");
              return false;
            }
            if (this.form.cardId == "" || this.form.cardId == null) {
              this.msgError("身份证号不能为空！");
              return false;
            }
            if (this.form.phoneNumber == "" || this.form.phoneNumber == null) {
              this.msgError("手机号码不能为空！");
              return false;
            }
            updatePerson(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.openedit = false;
              this.getList();
            });
          } else {
            if (this.form.personName == "" || this.form.personName == null) {
              this.msgError("姓名不能为空！");
              return false;
            }
            if (this.form.cardId == "" || this.form.cardId == null) {
              this.msgError("身份证号不能为空！");
              return false;
            }
            if (this.form.phoneNumber == "" || this.form.phoneNumber == null) {
              this.msgError("手机号码不能为空！");
              return false;
            }
            addPerson(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.form = {
                deptId: "",
              };
              this.openedit = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      this.personIdaaa = [row.personId];
      this.dialogdel = true;
    },
    /** 清空数据按钮操作 */
    getTruncateTable() {
      this.dialogdelA = true;
    },
    handleDeleteMultiple() {
      this.personIdaaa = this.ids;
      this.dialogdel = true;
    },
    // 删除确定
    delsure() {
      if (this.reason == "") {
        this.msgError("删除理由不能为空！");
        return false;
      }
      let parms = {
        personIds: this.personIdaaa,
        reason: this.reason,
      };
      removePerson(parms).then((res) => {
        if (res.code == 200) {
          this.dialogdel = false;
          this.msgSuccess("删除成功");
          this.personIdaaa = "";
          this.reason = "";
          this.getList();
        }
      });
    },
    // 删除取消
    delcal() {
      this.dialogdel = false;
      this.personIdaaa = "";
      this.reason = "";
    },

    // 清空确认
    delsureA() {
      getTruncateTable().then((res) => {
        if (res.code == 200) {
          this.dialogdelA = false;
          this.msgSuccess("清空成功");
          this.getList();
        }
        if (res.code == 500) {
          this.dialogdelA = false;
          this.msgSuccess("清空成功");
          this.getList();
        }
      });
    },
    // 取消清空
    delcalA() {
       this.dialogdelA = false;
    },


    /** 负责人下拉框 */
    personchargeList() {
      personchargelist().then((res) => {
        this.fuzeren = res.data;
      });
    },
    /** 类别下拉框 */
    categorychargeList() {
      categorychargelist().then((res) => {
        this.category = res.data;
      });
    },
    /** 审核按钮操作 */
    toexamine(row) {
      if (!row.detectionCycleId) {
        this.$message.warning("请先修改此人的类别");
        return;
      }
      this.dialogVisible = true;
      this.personIdsss = row.personId;
    },
    // 审核通过
    adopt() {
      let parms = {
        personId: this.personIdsss,
        examine: 0,
      };
      updatePerson(parms).then((res) => {
        this.msgSuccess("审核通过成功");
        this.dialogVisible = false;
        this.getList();
      });
    },
  },
};
</script>
